package com.irdstudio.tdp.console.api.rest;

import java.util.ArrayList;
import java.util.List;

import com.irdstudio.tdp.console.service.vo.BatBatchStageConfigVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.irdstudio.sdk.beans.core.vo.ResponseData;
import com.irdstudio.sdk.ssm.web.AbstractController;
import com.irdstudio.tdp.console.service.facade.BatBatchStageConfigService;

@RestController
@RequestMapping("/api")
public class BatBatchStageConfigController extends AbstractController  {
	
	@Autowired
	@Qualifier("stageConfigService")
	private BatBatchStageConfigService batBatchStageConfigService;

	
	/**
	 * 列表数据查询
	 * @param page
	 * @param size
	 * @return
	 */
	@RequestMapping(value="/bat/batch/stage/configs", method=RequestMethod.POST)
	public @ResponseBody ResponseData<List<BatBatchStageConfigVO>> queryBatBatchStageConfigAll(
			BatBatchStageConfigVO vo) {		
		List<BatBatchStageConfigVO> outputVo = batBatchStageConfigService.queryAllOwner(vo);
		return getResponseData(outputVo);
		
	}
	
	/**
	 * 根据主键查询详情
	 * @return
	 */
	@RequestMapping(value="/bat/batch/stage/config/{stageId}/{batchId}", method=RequestMethod.GET)
	public @ResponseBody ResponseData<BatBatchStageConfigVO> queryByPk(@PathVariable("stageId") String stageId,@PathVariable("batchId") String batchId) {		
		BatBatchStageConfigVO inVo = new BatBatchStageConfigVO();
				inVo.setStageId(stageId);
				inVo.setBatchId(batchId);
		BatBatchStageConfigVO outputVo = batBatchStageConfigService.queryByPk(inVo);
		return getResponseData(outputVo);
		
	}
	
	/**
	 * 根据主键删除信息
	 * @param batBatchStageConfig
	 * @return
	 */
	@RequestMapping(value="/bat/batch/stage/config", method=RequestMethod.DELETE)
	public @ResponseBody ResponseData<Integer> deleteByPk(@RequestBody BatBatchStageConfigVO inBatBatchStageConfigVo) {		
		int outputVo = batBatchStageConfigService.deleteByPk(inBatBatchStageConfigVo);
		return getResponseData(outputVo);
		
	}
	
	/**
	 * 根据主键更新信息
	 * @param inBatBatchStageConfigVo
	 * @return
	 */
	@RequestMapping(value="/bat/batch/stage/config", method=RequestMethod.PUT)
	public @ResponseBody ResponseData<Integer> updateByPk(@RequestBody BatBatchStageConfigVO inBatBatchStageConfigVo) {		
		int outputVo = batBatchStageConfigService.updateByPk(inBatBatchStageConfigVo);
		return getResponseData(outputVo);
		
	}
	
	/**
	 * 新增数据
	 * @param inBatBatchStageConfigVo
	 * @return
	 */
	@RequestMapping(value="/bat/batch/stage/config", method=RequestMethod.POST)
	public @ResponseBody ResponseData<Integer> insertBatBatchStageConfig(@RequestBody BatBatchStageConfigVO inBatBatchStageConfigVo) {
		int outputVo = batBatchStageConfigService.insertBatBatchStageConfig(inBatBatchStageConfigVo);
		return getResponseData(outputVo);
		
	}
	
	/**
	 * 查询阶段字典项，给页面选择使用
	 * @param batchId 批次标识
	 * @return easyui识别的字典格式
	 */
	@RequestMapping(value="/bat/batch/stage/dics/{batchId}", method=RequestMethod.POST,produces="text/html;charset=UTF-8")
	public @ResponseBody String aBatBatchStageConfig(@PathVariable("batchId") String batchId) {
		BatBatchStageConfigVO inVo = new BatBatchStageConfigVO();
		inVo.setBatchId(batchId);
		List<BatBatchStageConfigVO> outputVo = batBatchStageConfigService.queryAllOwner(inVo);
		List<JSONObject> list = new ArrayList<JSONObject>();
		JSONObject json = null ;
		for (BatBatchStageConfigVO batBatchStageConfigVO : outputVo) {
			json = new JSONObject();
			json.put("enname", batBatchStageConfigVO.getStageId());
			json.put("cnname", batBatchStageConfigVO.getStageName());
			list.add(json);
		}
		return list.toString();
	}
	
}
